// See www.openfst.org for extensive documentation on this weighted
// finite-state transducer library.

#include <fst/extensions/linear/linearscript.h>

#include <fst/flags.h>

FST_DEFINE_string(arc_type, "standard", "Output arc type");

FST_DEFINE_string(epsilon_symbol, "<eps>", "Epsilon symbol");
FST_DEFINE_string(unknown_symbol, "<unk>", "Unknown word symbol");

FST_DEFINE_string(vocab, "", "Path to the vocabulary file");
FST_DEFINE_string(out, "", "Path to the output binary");

FST_DEFINE_string(save_isymbols, "", "Save input symbol table to file");
FST_DEFINE_string(save_fsymbols, "", "Save feature symbol table to file");
FST_DEFINE_string(save_osymbols, "", "Save output symbol table to file");

int main(int argc, char **argv) {
  // TODO(wuke): more detailed usage
  std::set_new_handler(FailedNewHandler);
  SET_FLAGS(argv[0], &argc, &argv, true);
  fst::script::ValidateDelimiter();
  fst::script::ValidateEmptySymbol();

  if (argc == 1) {
    ShowUsage();
    return 1;
  }

  fst::script::LinearCompile(FST_FLAGS_arc_type, FST_FLAGS_epsilon_symbol,
                                 FST_FLAGS_unknown_symbol, FST_FLAGS_vocab, argv + 1,
                                 argc - 1, FST_FLAGS_out, FST_FLAGS_save_isymbols,
                                 FST_FLAGS_save_fsymbols, FST_FLAGS_save_osymbols);
}
